<template>
<el-container class="home-container">
  <el-header>
    <div>
      <img src="http://weldon.net.cn/back/img/logo.5b13fac4.png" alt="" class="homelogo">
    </div>
    <el-button type="info" @click="loginout">退出</el-button>
  </el-header>
  <el-container>
    <el-aside :width="isCollapse? '64px':'200px'">
      <div class="toggle-button" @click="toggleCollapse">|||</div>
      <!-- 侧边栏 -->
      <el-menu
      background-color="#313743"
      text-color="#fff"
      active-text-color="#3899ff"
      unique-opened
      :collapse="isCollapse"
      :collapse-transition="false"
      :router="true"
      :default-active="activePath"
      >
      <el-submenu :index="item.id + ''"
      v-for = 'item in menulist'
      :key="item.id"
      >
        <template slot="title">
          <i :class="iconsObj[item.id]"></i>
          <span>{{ item.authName }}</span>
        </template>
          <el-menu-item :index="'/' + subItem.path"
      v-for = 'subItem in item.children'
      :key="subItem.id"
      @click="saveNavStaTE('/' + subItem.path)"
      >
            <template slot="title">
          <i class="el-icon-menu"></i>
          <span>{{ subItem.authName }}</span>
        </template>
          </el-menu-item>
      </el-submenu>
    </el-menu>
    </el-aside>
    <el-main>
      
      <router-view></router-view>
    </el-main>
  </el-container>
</el-container>
</template>

<script>
export default {
  data() {
    return {
      menulist: [],
      iconsObj: {
        '125': 'el-icon-s-custom',
      '103': 'el-icon-s-tools',
      '101': 'el-icon-s-goods',
      '102': 'el-icon-s-claim',
      '145': 'el-icon-data-line',
      },
      isCollapse: false,
      activePath:''
    }
  },
  created() {
    this.getMenuList()
    this.activePath = window.sessionStorage.getItem('activePath');
  },
  methods: {
    loginout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    async getMenuList() {
      const { data: res}=await this.$http.get('menus')
      // console.log(res);
      if(res.meta.status!==200) return this.$message.error(res.meta.msg)
      this.menulist = res.data
    },
    toggleCollapse() {
      this.isCollapse=!this.isCollapse
    },
    saveNavStaTE(activePath) {
      window.sessionStorage.setItem('activePath',activePath)
    }
  } 
}
</script>

<style lang="less" scoped>
.home-container{
  height: 100%;
}
.el-header{
  // height: 100%;
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: white;
  font-size: 20px;
  > div{
    display:flex;
    align-items:center;
    .homelogo{
      width: 240px;
      height: 100%;
    }
  };
}
.el-aside{
  // height: 100%;
  background-color: #333744;
  .toggle-button{
    background-color: #475163;
    color: #fff;
    font-size: 10px;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
  .el-menu{
    border-right: none;
  }
}
.el-main{
  // height: 100%;
  // display: flex;
  // align-items: center;
  background-color: #eaedf1;

}
.iconfont{
  margin-right: 10px;
}
</style>